<?php
/**
 ***********************************************************************************************************************
 * 服务单例实现类
 ***********************************************************************************************************************
 */
namespace soa;
use soa\BasicInfo\Branch;
use soa\BasicInfo\Counterman;
use soa\BasicInfo\Shop;
use soa\certificates\IDCard;
use soa\core\image;
use soa\core\moge;
use soa\delivery\Ane;
use soa\delivery\sto;
use soa\delivery\zt;
use soa\gzh\gzh;
use soa\message\stoExpressAlipay;
use soa\message\stoOrderAlipay;
use soa\message\userInfoAlipay;
use soa\parter\sto\serviceWindow;
use soa\parter\sto\StoDelivery;
use soa\parter\sto\thermalPaper;
use soa\parter\zt\courier;
use soa\parter\zt\pda;
use soa\partner\ane\AneClient;
use soa\partner\zt\ztThermalPaper;

//use soa\express\shop\shop;

/**
 * Class service
 * @package soa
 */
class service
{
    /**
     * 上次调用服务返回状态码 0表示正确 其他表示错误
     *
     * @return int
     */
    public function last_srv_code()
    {
        return client::$_code;
    }

    /**
     * 上次调用服务返回错误消息
     *
     * @return string
     */
    public function last_srv_msg()
    {
        return client::$_msg;
    }

    /**
     * 上次调用服务返回错误状态 0表示正确 其他表示错误
     *
     * @return int
     */
    public function last_srv_error()
    {
        return client::$_error;
    }

    /**
     * 上次调用服务返回原始结果
     *
     * @return mixed
     */
    public function last_srv_data()
    {
        return client::$_result;
    }

    /**
     * 通用服务
     * @var
     */
    private static $service;

    /**
     * 通用服务
     * @return apply
     */
    public static function service()
    {
        if (empty($service)) {
            self::$service = new \soa\apply();
        }
        return self::$service;
    }

    /**
     * 网点服务
     *
     * @var shop
     */
    private static $shopService;

    /**
     * 网点服务
     *
     * @return shop
     */
    public static function shop()
    {
        if(empty(self::$shopService)) {
            self::$shopService = new Shop();
        }
        return self::$shopService;
    }

/*    private static $shop2Service;
    public static function shop2()
    {
        if(empty(self::$shop2Service)) {
            self::$shop2Service = new Shop2();
        }
        return self::$shop2Service;
    }*/

    /**
     * 网点官方数据服务
     * tbl_branch_list
     */
    private static $branchService;
    public static function branch()
    {
        if(empty(self::$branchService))
            self::$branchService = new Branch();
        return self::$branchService;
    }


    /**
     * 申通E3快递员服务
     * @var \soa\parter\sto\courier
     */
    private static $stoCourierService;

    /**
     * 申通E3快递员服务
     * @return \soa\parter\sto\courier
     */
    public static function getStoCourierService()
    {
        if(empty(self::$stoCourierService)) {
            self::$stoCourierService = new \soa\parter\sto\courier();
        }
        return self::$stoCourierService;
    }

    /**
     * 申通E3快递员服务
     * @return \soa\parter\sto\courier
     */
    public static function stoCourier()
    {
        if(empty(self::$stoCourierService)) {
            self::$stoCourierService = new \soa\parter\sto\courier();
        }
        return self::$stoCourierService;
    }

    /**
     * 申通E3网点服务
     * @var \soa\parter\sto\branch
     */
    private static $stoBranchService;

    /**
     * 申通E3网点服务
     * @return \soa\parter\sto\branch
     */
    public static function getStoBranchService()
    {
        if(empty(self::$stoBranchService)) {
            self::$stoBranchService = new \soa\parter\sto\branch();
        }
        return self::$stoBranchService;
    }

    /**
     * 申通E3网点服务
     * @return \soa\parter\sto\branch
     */
    public static function stoBranch()
    {
        if(empty(self::$stoBranchService)) {
            self::$stoBranchService = new \soa\parter\sto\branch();
        }
        return self::$stoBranchService;
    }


    /**
     * 快递员服务
     * @var account\courier
     */
    private static $courierService;

    /**
     * 快递员服务
     * @return account\courier
     */
    public static function getCourierService()
    {
        if(empty(self::$courierService)) {
            self::$courierService = new \soa\account\courier();
        }
        return self::$courierService;
    }

    /**
     * 简写 快递员服务
     * @return account\courier
     */
    public static function courier()
    {
        if(empty(self::$courierService)) {
            self::$courierService = new \soa\account\courier();
        }
        return self::$courierService;
    }

    /**
     * @var
     */
    private static $userService;

    /**
     * @return account\user
     */
    public static function user()
    {
        if(empty(self::$userService)) {
            self::$userService = new \soa\account\user();
        }
        return self::$userService;
    }

    /**
     * 网点后台账号服务
     * @var account\wdadmin
     */
    private static $wdadminService;
    /**
     * 网点后台账号服务
     * @return account\wdadmin
     */
    public static function wdadmin()
    {
        if(empty(self::$wdadminService)) {
            self::$wdadminService = new \soa\account\wdadmin();
        }
        return self::$wdadminService;
    }


    /**
     * 邮件服务
     * @var message\mail
     */
    private static $mailService;

    /**
     * 邮件服务
     * @return message\mail
     */
    public static function getMailService()
    {
        if(empty(self::$mailService)) {
            self::$mailService = new \soa\message\mail();
        }
        return self::$mailService;
    }

    /**
     * 邮件服务
     * @return message\mail
     */
    public static function mail()
    {
        if(empty(self::$mailService)) {
            self::$mailService = new \soa\message\mail();
        }
        return self::$mailService;
    }


    /**
     * 短信服务
     * @var core\sms
     */
    private static $smsService;

    /**
     * 短信服务
     * @return core\sms
     */
    public static function getSmsService()
    {
        if(empty(self::$smsService)) {
            self::$smsService = new \soa\core\sms();
        }
        return self::$smsService;
    }

    /**
     * 短信服务
     * @return core\sms
     */
    public static function sms()
    {
        if(empty(self::$smsService)) {
            self::$smsService = new \soa\core\sms();
        }
        return self::$smsService;
    }

    /**
     * 推送服务
     * @var message\push
     */
    private static $pushService;

    /**
     * 推送服务
     * @return message\push
     */
    public static function push()
    {
        if(empty(self::$pushService)) {
            self::$pushService = new \soa\message\push();
        }
        return self::$pushService;
    }



    /**
     * 别混淆 这里是网点的服务信息 使用的是tbl_shop_server数据表
     * @var \soa\express\shop\service
     */
    private static $shopServiceService;

    /**
     * 网点的服务信息
     * @return \soa\express\shop\service
     */
    public static function shopService()
    {
        if(empty(self::$shopServiceService)) {
            self::$shopServiceService = new \soa\express\shop\service();
        }
        return self::$shopServiceService;
    }


    /**
     * 网点服务地区
     * @var \soa\express\shop\scope
     */
    private static $shopScope;

    /**
     * 网点服务地区
     * @return \soa\express\shop\scope
     */
    public static function shopScope()
    {
        if(empty(self::$shopScope)) {
            self::$shopScope = new \soa\express\shop\scope();
        }
        return self::$shopScope;
    }

    /**
     * 网点取派范围服务
     * @var \soa\express\shop\range
     */
    private static $shopRange;

    /**
     * 网点取派范围服务
     * @return \soa\express\shop\range
     */
    public static function shopRange()
    {
        if(empty(self::$shopRange)) {
            self::$shopRange = new \soa\express\shop\range();
        }
        return self::$shopRange;
    }

    /**
     * 网点超派范围服务
     * @var \soa\express\shop\overstep
     */
    private static $shopOverstep;

    /**
     * 网点超派范围服务
     * @return \soa\express\shop\overstep
     */
    public static function shopOverstep()
    {
        if(empty(self::$shopOverstep)) {
            self::$shopOverstep = new \soa\express\shop\overstep();
        }
        return self::$shopOverstep;
    }


    /**
     * 地区服务
     * @var \soa\core\map\area
     */
    private static $areaService;

    /**
     * 地区服务
     * @return \soa\core\map\area
     */
    public static function area()
    {
        if(empty(self::$areaService)) {
            self::$areaService = new \soa\core\map\area();
        }
        return self::$areaService;
    }

    /**
     * 地区服务
     * @var \soa\core\map\geo
     */
    private static $geoService;

    /**
     * 地区服务
     * @return \soa\core\map\geo
     */
    public static function geo()
    {
        if(empty(self::$geoService)) {
            self::$geoService = new \soa\core\map\geo();
        }
        return self::$geoService;
    }


    /**
     * 品牌服务
     * @var \soa\express\express\brand
     */
    private static $brandService;

    /**
     * 品牌服务
     * @return \soa\express\express\brand
     */
    public static function brand()
    {
        if(empty(self::$brandService)) {
            self::$brandService = new \soa\express\express\brand();
        }
        return self::$brandService;
    }

    /**
     * 中通快递员
     * @var \soa\parter\zt\courier
     */
    private static $ztoCourier;

    /**
     * 中通快递员
     * @return \soa\parter\zt\courier
     */
    public static function getZtoCourier()
    {
        if(empty(self::$ztoCourier)) {
            self::$ztoCourier = new courier();
        }
        return self::$ztoCourier;
    }

    /**
     * @var
     */
    private static $certificates;

    /**身份证图片识别
     * @return IDCard
     */
    public static function IDCardService()
    {
        if(empty(self::$certificates)) {
            self::$certificates = new IDCard();
        }
        return self::$certificates;
    }

    /**
     * @var
     */
    private static $imageService;

    /**
     * @return image
     */
    public static function getImageService()
    {
        if(empty(self::$imageService)) {
            self::$imageService = new image();
        }

        return self::$imageService;
    }

    /**
     * @var
     */
    private static $StoServices;

    /**
     * 申通相关业务服务
     * @return serviceWindow
     */
    public static function getStoService()
    {
        if(empty(self::$StoServices)) {
            self::$StoServices = new serviceWindow();
        }

        return self::$StoServices;
    }

    /**
     * 申通的alipay服务窗
     * @var
     */
    private static $alipayServiceWindowSto;

    /**
     * alipay service window
     * @return stoExpressAlipay
     */
    public static function alipayServiceWindowSto()
    {
        if(empty(self::$alipayServiceWindowSto))
            self::$alipayServiceWindowSto = new stoExpressAlipay();

        return self::$alipayServiceWindowSto;
    }

    /**
     * @var
     */
    private static $alipayUser;

    /**
     * alipay 用户账号的相关信息（登录申通服务窗的用户信息）
     * @return userInfoAlipay
     */
    public static function getAlipayUser()
    {
        if(empty(self::$alipayUser))
            self::$alipayUser = new userInfoAlipay();

        return self::$alipayUser;
    }

    /**
     * @var
     */
    private static $orderAlipaySto;

    /**
     * 申通订单受理通知发件人
     * @return stoOrderAlipay
     */
    public static function getOrderAlipaySto()
    {
        if(empty(self::$orderAlipaySto))
            self::$orderAlipaySto = new stoOrderAlipay();

        return self::$orderAlipaySto;
    }

    /**
     * 中通巴枪服务
     * @var
     */
    private static $ztPdaService;

    /**
     * 获取中通巴枪服务
     * @return pda
     */
    public static function getZtPdaService()
    {
        if(empty(self::$ztPdaService))
            self::$ztPdaService = new pda();

        return self::$ztPdaService;
    }

    /**
     * 申通派件清单
     * @var
     */
    public static $stoDeliveryListService;

    /**
     * 获取申通派件清单服务
     * @return StoDelivery
     */
    public static function getStoDeliveryListService()
    {
        if(empty(self::$stoDeliveryListService)){
            //self::$stoDeliveryListService = new delivery();//老接口服务
            self::$stoDeliveryListService = new StoDelivery();//新接口服务,新接口还没开放
        }

        return self::$stoDeliveryListService;
    }

    /**
     * 中通派件清单
     * @var
     */
    private static $ztoDeliveryListService;

    /**
     * 获取中通派件清单服务
     * @return parter\zt\delivery
     */
    public static function getZtoDeliveryListService()
    {
        if(empty(self::$ztoDeliveryListService))
            self::$ztoDeliveryListService = new \soa\parter\zt\delivery();

        return self::$ztoDeliveryListService;
    }

    /**
     * 申通派件内部服务service
     * @var
     */
    private static $stoPai;

    /**
     * 获取申通派件内部服务service
     * @return sto
     */
    public static function getStoPai()
    {
        if(empty(self::$stoPai))
            self::$stoPai = new sto();
        
        return self::$stoPai;
    }

    /**
     * 中通派件清单
     * @var
     */
    private static $ztPi;

    /**
     * 中通派件清单
     * @return zt
     */
    public static function getZtoPai()
    {
        if(empty(self::$ztPi))
            self::$ztPi = new zt();
        
        return self::$ztPi;
    }
    /**
     * 申通电子面单
     * @var
     */
    private static $stoThermalPaperService;

    /**
     * 申通电子面单
     * @return thermalPaper
     */
    public static function getStoThermalPaperService()
    {
        if(empty(self::$stoThermalPaperService)) {
            self::$stoThermalPaperService = new thermalPaper();
        }
        
        return self::$stoThermalPaperService;
    }

    /**
     * 中通电子面单（edited by zzx）
     * @var
     */
    private static $ztThermalPaperService;

    /**
     * 中通电子面单（edited by zzx）
     * @return thermalPaper
     */
    public static function getZtThermalPaperService($zto_partner,$zto_pass)
    {
        if(empty(self::$ztThermalPaperService)) {
            self::$ztThermalPaperService = new ztThermalPaper($zto_partner,$zto_pass);
        }
         
        return self::$ztThermalPaperService;
    }

    /**
     * 聚宝魔格货栈合作
     * 
     * @var moge
     */
    private static $jubaomoge;

    /**
     * 聚宝魔格货栈合作
     *
     * @return moge
     */
    public static function moge()
    {
        if(empty(self::$jubaomoge)) {
            self::$jubaomoge = new moge();
        }
        return self::$jubaomoge;
    }

    /**
     * @var
     */
    private static $gzh;

    /**
     * @return moge|gzh
     */
    public static function gzh()
    {
        if(empty(self::$gzh)) {
            self::$gzh = new gzh();
        }
        return self::$gzh;
    }

    /**
     * 安能物流通用上传接口服务
     *
     * @var
     */
    private static $aneService;

    /**
     * 安能物流通用上传接口服务
     *
     * @return AneClient
     */
    public static function aneService()
    {
        if(empty(self::$aneService)) {
            self::$aneService = new AneClient();
        }
        return self::$aneService;
    }

    /**
     * 安能派件清单服务
     *
     * @var
     */
    private static $aneDeliveryListService;

    /**
     * 获取安能派件清单服务
     *
     * @return partner\ane\Delivery
     */
    public static function getAneDeliveryListService()
    {
        if(empty(self::$aneDeliveryListService))
            self::$aneDeliveryListService = new \soa\partner\ane\Delivery();

        return self::$aneDeliveryListService;
    }

    /**
     * 安通派件内部服务service
     *
     * @var
     */
    private static $anePai;

    /**
     * 获取安能派件内部服务service
     *
     * @return Ane
     */
    public static function getAnePai()
    {
        if(empty(self::$anePai))
            self::$anePai = new Ane();

        return self::$anePai;
    }

    /**
     * @var
     */
    private static $order;

    /**
     * @return order\order
     */
    public static function order()
    {
        if (empty(self::$order)) {
            self::$order = new \soa\order\order();
        }

        return self::$order;
    }

    /**
     * @var
     */
    private static $record;

    /**
     * @return account\record
     */
    public static function record()
    {
        if (empty(self::$record)) {
            self::$record = new \soa\account\record();
        }

        return self::$record;
    }

    /**
     * @var
     */
    private static $wduser;

    /**
     * @return order\order
     */
    public static function wduser()
    {
        if (empty(self::$wduser)) {
            self::$wduser = new \soa\wduser\Wduser();
        }

        return self::$wduser;
    }

    /**
     * 获取官方快递员信息服务
     * tbl_counterman_phone数据表
     */
    private static $counterman;

    public static function counterman()
    {
        if(empty(self::$counterman))
            self::$counterman = new Counterman();

        return self::$counterman;
    }

    private static $scanCourier;

    /**
     * 获取快递员app绑定巴枪的快递员信息
     * @return BasicInfo\scanCourier
     */
    public static function scanCourier()
    {
        if (empty(self::$scanCourier)) {
            self::$scanCourier = new \soa\BasicInfo\scanCourier();
        }

        return self::$scanCourier;
    }
}